package com.ruoyi.info.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.health.domain.Activity;
import com.ruoyi.health.domain.vo.ActivityVo;
import com.ruoyi.health.service.IActivityService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动风采管理Controller
 * 
 * @author dalian
 * @date 2023-08-06
 */
@RestController
@RequestMapping("/info/healthActivity")
public class FrontActivityController extends BaseController
{
    @Autowired
    private IActivityService activityService;

    /**
     * 查询活动风采管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ActivityVo activityVo)
    {
        //重新封装查询条件
        Activity activity = new Activity();
        //处理三级id查询条件
        if(activityVo.getRegionId()!=null){
            BeanUtils.copyProperties(activityVo,activity);  //自带regionId
        } else if(activityVo.getRegion3Id()!=null){
            BeanUtils.copyProperties(activityVo,activity);
            activity.setRegionId(activityVo.getRegion3Id());  //带region3Id
        }else if(activityVo.getRegion2Id()!=null){
            BeanUtils.copyProperties(activityVo,activity);
            activity.setRegionId(activityVo.getRegion2Id());    //带region2Id
        }else{
            BeanUtils.copyProperties(activityVo,activity);
            activity.setRegionId(activityVo.getRegion1Id());    //带region1Id
        }

        startPage();
        List<Activity> list = activityService.selectActivityList(activity);
        return getDataTable(list);
    }



    /**
     * 获取活动风采管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityService.selectActivityById(id));
    }

}
